home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / viewkit / xcontact / include / Database.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.7 KB  |  154 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. //////////////////////////////////////////////////////////////
  18. // Database.h --
  19. //////////////////////////////////////////////////////////////
  20. #ifndef DATABASE_H
  21. #define DATABASE_H
  22.  
  23.  
  24.  
  25. #include "parody.h"
  26. #include "OkStr.h"
  27. #include "OkStrArray.h"
  28. #include "OkTPtrArray.h"
  29.  
  30.  
  31. enum ClassIdent {
  32.   SETUP_FIELDS=1,
  33.   SETUP_ATTRIBUTES,
  34.   CARD_DIRECTORY,
  35.   FIELDS_SETUP,
  36.   CARD_INFO
  37. };
  38.  
  39.  
  40. // Generic Integer Key.
  41.  
  42. class IntKey : public Key {
  43.   int _key;
  44.  
  45.   int operator>( Key &key )    { return _key>((IntKey &) key).key(); }
  46.   int operator==( Key &key )    { return _key==((IntKey &) key).key(); }
  47.  
  48.   Key& operator=( Key &key )    { 
  49.     if ( this != &key ) {
  50.       Key::operator=(key);
  51.       IntKey& intKey = (IntKey&) key;
  52.       _key = intKey._key;
  53.     }
  54.     return *this;
  55.   }
  56.  
  57.   void Write( fstream& ndx )    { ndx.write( (char *) &_key, sizeof _key ); }
  58.   void Read( fstream& ndx )    { ndx.read( (char *) &_key, sizeof _key ); }
  59.  
  60.   Key *Make()            { return new IntKey(); }
  61.   pBool isNullValue()        { return (pBool) ( _key==0 ); }
  62.  
  63.  public:
  64.   IntKey( int key=0 )        { _key = key; }
  65.   int key() const        { return _key; }
  66. };
  67.  
  68. enum SortOrder { ASCENDING, DESCENDING };
  69.  
  70. typedef OkTPtrArray<ObjAddr> ObjAddrArray;
  71.  
  72. class CardDirectory : public Persistent {
  73.  
  74.   IntKey    _key;
  75.   ObjAddrArray    _objAddrArray;
  76.   SortOrder    _sortOrder;
  77.  
  78.  public:
  79.   CardDirectory();
  80.   ~CardDirectory();
  81.  
  82.   ObjAddr objAddr( unsigned pos )     { return _objAddrArray[ pos-1 ]; }
  83.  
  84.   unsigned totalCards()         { return _objAddrArray.length(); }
  85.   void add( ObjAddr objAddr, unsigned pos=0 );
  86.   void remove( unsigned pos );
  87.   void removeAll();
  88.  
  89.   void sort( SortOrder );
  90.   SortOrder sortOrder() const         { return _sortOrder; }
  91.  
  92.  
  93.  protected:
  94.   // Persistent funcs.
  95.   void Read();
  96.   void Write();
  97.  
  98. };
  99.  
  100.  
  101. class CardInfo;
  102. class ExportImportDialog;
  103.  
  104. class Database : public Parody {
  105.  
  106.   friend ExportImportDialog;
  107.   
  108.   CardDirectory*    _cardDirectory;
  109.  
  110.  private:
  111.   OkStr     _dbName;
  112.  
  113.   Boolean     _dirty;
  114.  
  115.  public:
  116.   Database( const char* name );
  117.   ~Database();
  118.   void save();
  119.  
  120.   const char* dbName() const     { return _dbName; }
  121.   int totalCards() const        { return _cardDirectory->totalCards(); }
  122.  
  123.   // Caller is responsible to delete returned CardInfo from 
  124.   // cardInfo and addCard.
  125.   // pos = {1 ... totalCards)
  126.   CardInfo* cardInfo( unsigned pos ); 
  127.   CardInfo* addCard( const char* name, unsigned pos=0 );
  128.   CardInfo* addCard( CardInfo* cInfo, unsigned pos=0 );
  129.  
  130.   void deleteCard( unsigned pos, CardInfo* cInfo=NULL );
  131.   void deleteAllCards();
  132.  
  133.   void load( OkStr& listHeader, OkStrArray& listItems );
  134.   static void Load( OkStr& item, const CardInfo* cInfo );
  135.  
  136.   SortOrder sortOrder() const          { return _cardDirectory->sortOrder(); }
  137.   void sort( SortOrder sortOrder )    { _cardDirectory->sort( sortOrder ); }
  138.  
  139.   // Search card that has string s.
  140.   // Returns card number, or 0 if none found.
  141.   enum Direction { FORWARD, BACKWARD };
  142.   int searchCard( OkStr s, 
  143.           int from=0, 
  144.           Direction direction=FORWARD,
  145.                   Boolean caseSensitive=FALSE, 
  146.           Boolean srchNotesToo=FALSE );
  147.  
  148. };
  149.  
  150. extern Database *theDatabase;
  151.  
  152.  
  153. #endif
  154.